package main

import (
	"fmt"
	"time"
)

type field struct {
	name string
}

func (p field) print() {
	fmt.Println(p.name)
}

// 值接收者方法，操作的是副本
func (p field) set(val string) {
	p.name = val
}

func main() {
	data1 := []*field{&field{"one"}, {"two"}, {"three"}}
	// data1[0].set("111")
	// data1[0].name = "111"
	data1[0].set("111")
	data1[1].name = "222"
	fmt.Println(data1)

	for _, v := range data1 {
		go v.print()
		// go func() {
		// 	v.print()
		// 	// fmt.Println(&v)
		// 	// fmt.Printf("type of current v is:%T\n", v) // *main.field （指针类型的 field 实例）
		// }()

		time.Sleep(50 * time.Millisecond)
	}

	data2 := []field{field{"four"}, {"five"}, {"six"}}
	data2[0].set("444")
	data2[0].name = "555"
	// data2[0].name = "444"
	// fmt.Println(data2)
	for _, v := range data2 {
		go v.print()
		// go func() {
		// 	v.print()
		// 	// fmt.Println(v)
		// 	// fmt.Printf("type of current v is:%T\n", v) // main.field
		// }()

		time.Sleep(50 * time.Millisecond)
	}

	time.Sleep(1 * time.Second)
}
